﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Models;
using DAL;

namespace BLL
{
    public class CharManager
    {
        CharService cs = new CharService();

        public DataView GetAllChar()
        {
            DataView dvChar = new DataView();
            dvChar.Table = dvChar.Table = cs.GetAllChar().Tables["CharTable"];
            return dvChar;
        }

        public void Page(int i)
        {
            switch (i)
            {
                case 0:
                    if (cs.pageCurrent == 0)//判断是否是第一页
                    {
                        break;
                    }
                     cs.pageCurrent -= cs.pageSize;
                     break;
                case 1:
                     cs.pageCurrent += cs.pageSize;
                    break;
            }
        }

        public int PageSize()//每页显示的行
        {
            int i = cs.pageSize;
            return i;
        }

        public DataView Search(string search,int i)//查询
        {
            DataView dvChar = new DataView();
            dvChar.Table = dvChar.Table = cs.GetSearchChar().Tables["SearchCharTable"];
            switch (i)
            {
                case 0:
                    dvChar.RowFilter = string.Format("account_name like '%{0}%'", search);
                    //dvChar.RowFilter = string.Format("account_name ='{0}'", search);
                    break;
                case 1:
                    dvChar.RowFilter = string.Format("char_name like '%{0}%'", search);
                    //dvChar.RowFilter = string.Format("char_name = '{0}'", search);
                    break;
            }
            return dvChar;
        }

        public string Account(string account, string pwd, int AccType)
        {
            int i =cs.Account(account, pwd, AccType);
            if (i==1582)
            {
                return "账号已经存在";
            }
            if (i == 1)
            {
                return "提交成功";
            }
            return "提交失败";
        }
    }
}
